

function say() {
    alert("LC:671. 二叉树中第二小的节点");
}
say();

/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var findSecondMinimumValue = function(root) {

    var set = new Set()
    dfs(root, set)
    var arr = Array.from(set)
    if(arr.length > 1){
        arr.sort(function(a , b){
            return a - b
        })
        return arr[1]
    }else {
        return -1
    }
};

function dfs(root, set) {
    if(root) {
        set.add(root.val)
        dfs(root.left, set)
        dfs(root.right, set)
    }
}
